<template>
  <view class="safe-area-inset-bottom">
    <view class="swip_header">
      <view class="slot-box">
        <view style="width: 100%;">
          <uni-search-bar
              v-model="queryParams.params.findApi"
              type="text"
              @confirm="handleQuery"
              @input="handleQuery"
              placeholder="请输入订单名称/编号"/>
        </view>
      </view>
    </view>

    <view class="listSearchTop" v-if="dataList != ''">
      <uni-card :is-shadow="false" v-for="(item,index) in dataList" :key="index">
        <p class="grid-integral">订单名称：{{ item.name }}</p>
        <p class="grid-integral">订单编号：{{ item.number }}</span></p>
        <p class="grid-integral">支付金额：{{ item.amount }}元</p>
        <p class="grid-integral">支付人：{{ item.payerName }}</p>
        <p class="grid-integral">支付时间：{{ item.payTime }}</p>
      </uni-card>
      <!-- 加载更多 -->
      <uni-load-more color="#00a660" :status="loadStatus"/>
    </view>
    <!-- 暂无数据 -->
    <luanqingEmpty :show="true" text="没有更多数据啦" v-else/>
  </view>
</template>

<script>
import {listOrderPayForInvoice} from "@/api/ec/console/fee/orderPay";
import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';

export default {
  components: {luanqingEmpty},
  data() {
    return {
      // 加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
      loadStatus: 'loading',
      // 订单ids
      orderPayId: '',
      // 数据列表
      dataList: [],
      //总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params: {
          findApi: undefined
        }
      },
    }
  },
  onLoad(option) {
    this.orderPayId = option.orderPayIds
  },
  created() {
    this.getList();
  },
  /** 上拉刷新回调 */
  onReachBottom() {
    if (this.loadStatus != 'noMore' && this.total > this.dataList.length) {
      this.loadStatus = 'loading';
      // 延迟500毫秒显示loading效果
      setTimeout(() => {
        // 执行查询的方法
        this.getList(false)
      }, 500)
    } else {
      // 停止加载
      this.loadStatus = 'noMore'
    }
  },
  methods: {
    /** 搜索 */
    handleQuery() {
      this.getList(true);
    },
    /** 查询列表 */
    getList(reload) {
      if (reload) {
        this.queryParams.pageNum = 1;
        this.loadStatus = 'more'
        this.$modal.loading();
      }
      this.queryParams.params.orderPayIds = this.orderPayId
      listOrderPayForInvoice(this.queryParams).then(response => {
        if (reload) {
          uni.hideLoading()
        }
        this.total = response.total;
        if (response.total > 0) {
          const dataRows = response.rows;
          this.dataList = reload ? dataRows : this.dataList.concat(dataRows);
        } else {
          this.dataList = [];
        }
        // 判断数据是否加载完全
        if (response.total <= this.dataList.length) {
          this.loadStatus = 'noMore'
        }
        // 页数+1
        this.queryParams.pageNum++
      }).catch(() => {
        if (reload) {
          uni.hideLoading()
        }
      });
    },
  }
}
</script>

<style scoped lang="scss">
page {
  background: $uni-bg-color-grey;
}
</style>
